package com.cyf.db.mapper.smartCity;

import com.cyf.db.bean.LocalInParking;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 车辆入场信息
 * Created by Administrator on 2017/5/31 0031.
 */
@Mapper
public interface LocalInParkingMapper {

    //根据 车牌号检查入场信息
    @Select("SELECT * FROM local_inparking WHERE plate=#{plate} AND status=0 order by id desc limit 0, 1")
    LocalInParking getByPlate(@Param("plate") String plate);

    @Select("SELECT * FROM local_inparking WHERE id = #{id}")
    LocalInParking getById(@Param("id") Integer id);

    @Select("<script>" +
            "select * from local_inparking " +
            "where status = 0 " +
            "   <if test=\" parkingId != 0 \">" +
            "      and parkingId = #{parkingId}" +
            "   </if>" +
            "   <if test=\" plate != null and plate != '' \">" +
            "      and plate like '${plate}%' " +
            "   </if>" +
            "   <if test=\" localFeegroupId != null and localFeegroupId != 0 \">" +
            "      and feeGroupId = #{localFeegroupId} " +
            "   </if>" +
            "   <if test=\" startTime != null and startTime != '' \">" +
            "      <![CDATA[ and primaryInTime >= '${startTime} 00:00:00' ]]> " +
            "   </if>" +
            "   <if test=\" endTime != null and endTime != '' \">" +
            "      <![CDATA[ and primaryInTime <= '${endTime} 23:59:59' ]]> " +
            "   </if>" +
            "" +
            "order by primaryInTime desc " +
            "limit #{start}, #{pageSize} " +
            "</script>")
    List<LocalInParking> listByCondition(
            @Param("parkingId") int parkingId,
            @Param("startTime") String startTime,
            @Param("endTime") String endTime,
            @Param("plate") String plate,
            @Param("localFeegroupId") Integer localFeegroupId,
            @Param("start") int start,
            @Param("pageSize") int pageSize);

    @Select("SELECT count(id) FROM local_inparking WHERE parkingId = #{parkingId} and plate=#{plate} AND status=0")
    Integer countByParkingIdAndPlate(@Param("parkingId") int parkingId, @Param("plate") String plate);


}